
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0830
 * @Author : WangRuoyu 
 * @Date : 2023/5/20 16:20
 */

#include "stack"
#include "iostream"

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    stack<int> s;
    s.push(-1);
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        while (s.top() >= x) s.pop();
        printf("%d ", s.top());
        s.push(x);
    }
    return 0;
}